using System.Collections.Generic;
using System.Xml.Linq;
using TickSharp.Core.Infrastructure.Serializers;
using TickSharp.Core.Interfaces;
using TickSharp.Core.Interfaces.Repositories;
using TickSharp.Core.Model;

namespace TickSharp.Core.Infrastructure.Repositories
{
    public class ClientRepository : RepositoryBase, IClientRepository
    {
        private readonly ISerializer<Client> _serializer;

        public ClientRepository(IApiConnectionInfo apiConnectionInfo, ISerializer<Client> serializer) : base(apiConnectionInfo)
        {
            _serializer = serializer;
        }

        public ClientRepository(IApiConnectionInfo apiConnectionInfo) : this(apiConnectionInfo, new ClientSerializer())
        {
        }

        /// <summary>
        /// Optional parameters:
        /// open (true|false)
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Client> List()
        {
            string uri = BuildUrl("clients", null);
            XElement elements = GetResponse(uri);
            return _serializer.Deserialize(elements);
        }
    }
}